package com.design_pattern._01_create._01_singleton;

public class TestDriver {
    public static void main(String[] args) throws InterruptedException {
        testV1();
        Thread.sleep(2000);
        testV2();
        Thread.sleep(2000);
        testV3();
        Thread.sleep(2000);
        testV4();
    }

    /**
     * 可以通过发射传递class，减少代码，但是这里为了测试，没必要搞得麻烦
     */
    private static void testV1() {
        for (int i = 0; i < 20; i++) {
            Thread thread = new Thread(() -> {
                V1 instance = V1.getInstance();
                System.out.println(instance);
            });
            thread.start();
        }
    }
    private static void testV2() {
        for (int i = 0; i < 20; i++) {
            Thread thread = new Thread(() -> {
                V2 instance = V2.getInstance();
                System.out.println(instance);
            });
            thread.start();
        }
    }
    private static void testV3() {
        for (int i = 0; i < 20; i++) {
            Thread thread = new Thread(() -> {
                V3 instance = V3.getInstance();
                System.out.println(instance);
            });
            thread.start();
        }
    }
    private static void testV4() {
        for (int i = 0; i < 20; i++) {
            Thread thread = new Thread(() -> {
                V4 instance = V4.getInstance();
                System.out.println(instance);
            });
            thread.start();
        }
    }
}

